package com.oglvip.business.remote.support;

import com.oglvip.business.remote.support.init.ServiceLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * static factory
 */
public class ServiceFactory{
	private static final Logger logger_ = LoggerFactory.getLogger(ServiceFactory.class);
	private final static Object object = new Object();
	public static <T> T getService(Class<T> clazz){
		
		ServiceLoader loader = new ServiceLoader("com");
		T service = loader.getService(clazz);
		if(service == null){
			synchronized (object) {
				if( loader.getServices().get(clazz.getName()) == null){
					loader.load(clazz);
					service = loader.getService(clazz);
				}
			}
		}
		if(service == null){
			logger_.warn(clazz.getName() + " load restclient wrong: null");
		}
		return service;
	}
	
	
}
